package com.heima.home.controller;

import com.heima.home.dto.PageResponse;
import com.heima.home.entity.Properties;
import com.heima.home.service.PropertyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/properties")
public class PropertyController {

    @Autowired
    private PropertyService propertyService;

    @GetMapping("/list")
    public ResponseEntity<PageResponse<Properties>> getPropertyList(
            @RequestParam(defaultValue = "1") int pageNum,
            @RequestParam(defaultValue = "8") int pageSize) {

        PageResponse<Properties> propertyPage = propertyService.getPropertyList(pageNum, pageSize);
        return ResponseEntity.ok(propertyPage);
    }
    
    @GetMapping("/{id}")
    public ResponseEntity<Properties> getPropertyById(
            @PathVariable Long id) {
        Properties property = propertyService.getPropertyById(id);
        return ResponseEntity.ok(property);
    }
}